import { createRouter, createWebHistory } from "vue-router";
import { defineAsyncComponent } from "vue";
import MainPage from "./pages/MainPage.vue";
// const MainPage = defineAsyncComponent(() => import("./pages/MainPage.vue"));
import LoginPage from "./pages/LoginPage.vue";
// const LoginPage = defineAsyncComponent(() => import("./pages/LoginPage.vue"));
import ErrorPage from "./pages/ErrorPage.vue";
// const ErrorPage = defineAsyncComponent(() => import("./pages/ErrorPage.vue"));
import SectionDetailPage from "./pages/SectionDetailPage.vue";
// const SectionDetailPage = defineAsyncComponent(
//   () => import("./pages/SectionDetailPage.vue"),
// );
import HomeworkPage from "./pages/AssignmentPage.vue";
// const HomeworkPage = defineAsyncComponent(
//   () => import("./pages/AssignmentPage.vue"),
// );
import DiscussionPage from "./pages/DiscussionPage.vue";
// const DiscussionPage = defineAsyncComponent(
//   () => import("./pages/DiscussionPage.vue"),
// );
import DiscussionList from "./components/discussion/DiscussionList.vue";
// const DiscussionList = defineAsyncComponent(
//   () => import("./components/discussion/DiscussionList.vue"),
// );
import ExamPreparePage from "./pages/exam/ExamPreparePage.vue";
// const ExamPreparePage = defineAsyncComponent(
//   () => import("./pages/exam/ExamPreparePage.vue"),
// );
import ExamWorkPage from "./pages/exam/ExamWorkPage.vue";
// const ExamWorkPage = defineAsyncComponent(
//   () => import("./pages/exam/ExamWorkPage.vue"),
// );
import ExamHistoryPage from "./pages/exam/ExamHistoryPage.vue";
// const ExamHistoryDetailPage = defineAsyncComponent(
//   () => import("./pages/exam/ExamHistoryDetailPage.vue"),
// );
import ExamHistoryDetailPage from "./pages/exam/ExamHistoryDetailPage.vue";
// const ExamHistoryPage = defineAsyncComponent(
//   () => import("./pages/exam/ExamHistoryPage.vue"),
// );
import ManagementPage from "./pages/ManagementPage.vue";
// const ManagementPage = defineAsyncComponent(
//   () => import("./pages/ManagementPage.vue"),
// );
import VideoPage from "./pages/VideoPage.vue";
// const VideoPage = defineAsyncComponent(() => import("./pages/VideoPage.vue"));
import ExamAlgorithmPage from "./pages/exam/ExamAlgorithmPage.vue";
// const ExamAlgorithmPage = defineAsyncComponent(
//   () => import("./pages/exam/ExamAlgorithmPage.vue"),
// );

const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: "/",
      component: MainPage,
      name: "home",
      children: [
        {
          path: "/:id(\\d+)",
          component: SectionDetailPage,
          meta: { isSection: true },
        },
      ],
    },
    {
      path: "/video/:id(\\d+)",
      component: VideoPage,
      meta: { isVideo: true },
    },
    {
      path: "/homework",
      component: HomeworkPage,
      name: "homework",
      meta: { isNeedLogin: true },
    },
    { path: "/login", component: LoginPage, name: "login" },
    {
      path: "/discussion",
      component: DiscussionList,
      name: "discussion",
    },
    {
      path: "/discussion/:id(\\d+)",
      component: DiscussionPage,
      name: "discussion_detail",
      meta: { isNeedLogin: true },
    },
    {
      path: "/exam_prepare",
      component: ExamPreparePage,
      name: "exam_prepare",
      meta: { isNeedLogin: true },
    },
    {
      path: "/exam_history",
      component: ExamHistoryPage,
      name: "exam_history",
      meta: { isNeedLogin: true },
    },
    {
      path: "/exam_history/:id(\\d+)",
      component: ExamHistoryDetailPage,
      name: "exam_history_detail",
      meta: { isNeedLogin: true },
    },
    {
      path: "/exam_history_algorithm/:id(\\d+)",
      component: ExamAlgorithmPage,
      name: "exam_history_algorithm_detail",
      meta: { isNeedLogin: true },
    },
    {
      path: "/manage",
      component: ManagementPage,
      name: "manage",
      meta: { isNeedLogin: true, isNeedAdmin: true },
    },
    {
      path: "/exam_work",
      component: ExamWorkPage,
      name: "exam_work",
      meta: { isNeedLogin: true },
    },
    { path: "/:error(.*)", component: ErrorPage },
  ],
});

export default router;
